import { ref, onMounted } from 'vue'
import { sysUserImage } from '@/api/user'

export default function () {
  const codeImg = ref<string>('') // 图片
  // 获取图片二进制流,并转为base64
  function getImage() {
    sysUserImage()
      .then((res: any) => {
        const str = String.fromCharCode(...new Uint8Array(res))
        codeImg.value = `data:image/png;base64,${window.btoa(str)}`
      })
      .catch(() => {})
  }
  onMounted(() => {
    getImage()
  })

  return { codeImg, getImage }
}
